import http from './http.js';
import store from '../store/index.js'

/**
 * 当前页面提供的JSAPI接口 用户登录即可调用
 * 不会检验操作的操作权限
 * */
//===================通用上传方法=================


export function fileUpload(file) {
    let url = `/internal/common/upload`;
    return new Promise((resolve, reject) => {
        http.upload(url, file).then(response => {
            resolve(response)
        });
    });
}



export function base64upImgage(base64Obj) {
    let url = `/internal/common/upload/base64`;
    return new Promise((resolve, reject) => {
        http.post(url, base64Obj).then(response => {
            resolve(response)
        })
    });
}




//====================后台管理模块的开放接口========================
//根据JWT获取员工信息
export function getOperatorInfo() {
    return new Promise(
        (resolve, reject) => {
            http.get("/internal/manager/operatorInfoByJwt",).then(response => {
                resolve(response)
            });
        });
}


//根据JWT信息修改密码
export function resetPassword(param) {
    return new Promise(
        (resolve, reject) => {
            http.put("/internal/manager/resetPasswordByJwt", param).then(response => {
                resolve(response)
            });
        });
}


//根据JWT获取员工菜单
export function getOperatorMenu() {
    return new Promise(
        (resolve, reject) => {
            http.get("/internal/manager/getMenuTreeByJwt",).then(response => {
                resolve(response)
            });
        });
}


//======================系统配置模块的开放接口========================

//根据字典代码返回字典选选项
export function dictLoad(code) {
    return new Promise((resolve, reject) => {
        //获取所有缓存的字典
        let dictList = store.state.dict;
        //已缓存的字典是否存在当前字典
        const dictmx = dictList.find(item => {
            return item.dictionaryCode === code;
        });
        if (dictmx === undefined) {
            let url = `/internal/system/dictionary/loadByCode/${code}`;
            http.get(url).then(response => {
                //查询结果加封装 存入sotre
                let newdata = {dictionaryCode: code, value: response.data.result}
                store.commit('setDict', newdata);
                resolve(response.data.result);
            });
        } else {
            resolve(dictmx.value)
        }
    });
}


//递归格式的菜单数据
export function menuRecursion(param) {
    let url = `/internal/system/menu/recursion`;
    return new Promise((resolve, reject) => {
        http.get(url, param).then(response => {
            resolve(response)
        });
    });
}


//======================人力资源模块的开放接口========================

//部门选择器数据加载
export function simpleTree() {
    let url = `/internal/hrms/dept/dict`;
    return new Promise((resolve, reject) => {
        http.get(url).then(response => {
            resolve(response)
        });
    });
}


//分组标签-数据字典
export function groupDict() {
    let url = `/internal/hrms/group/dict`;
    return new Promise((resolve, reject) => {
        http.get(url).then(response => {
            resolve(response.data.result)
        });
    });
}


//职务列表 数据字典
export function dictPosition() {
    let url = `/internal/hrms/position/dict`;
    return new Promise((resolve, reject) => {
        http.get(url).then(response => {
            resolve(response.data.result)
        });
    });
}


//使用Base64模式上传人员头像
export function base64upAvatar(base64Obj) {
    let url = `/internal/hrms/staff/upload/avatar`;
    return new Promise((resolve, reject) => {
        http.post(url, base64Obj).then(response => {
            resolve(response)
        })
    });
}


//人员档案 多条件搜索接口
export function staffByMultiple(pagination, param) {
    let url = `/internal/hrms/staff/multiple/${pagination.pageSize}/${pagination.current}`;
    return new Promise((resolve, reject) => {
        http.get(url, param).then(response => {
            resolve(response)
        });
    });
}


//人员档案- 关键字搜索接口
export function staffByKeyword(pagination, keyword) {
    let url = `/internal/hrms/staff/keyword/${pagination.pageSize}/${pagination.current}`;
    if (keyword !== "") {
        url += "/" + keyword;
    }
    return new Promise((resolve, reject) => {
        http.get(url).then(response => {
            resolve(response)
        })
    });
}

//=================微信小程序模块内部接口=================
//获取微信公众号配置参数
export function GetWeixinAppServer() {
    let url = `/internal/weixin/app/config/info`;
    return new Promise((resolve, reject) => {
        http.get(url).then(response => {
            resolve(response)
        });
    });
}



//=================微信公众号模块接口========================


//获取微信公众号配置参数
export function GetWeixinMpServer() {
    let url = `/internal/weixin/mp/config/info`;
    return new Promise((resolve, reject) => {
        http.get(url).then(response => {
            resolve(response)
        });
    });
}


//获取微信公众号素材文件列表
export function getMaterailFileList(pagination, param) {
    let url = `/internal/weixin/mp/material/list/${pagination.pageSize}/${pagination.current}`;
    return new Promise((resolve, reject) => {
        http.get(url, param).then(response => {
            resolve(response)
        });
    });
}


//根据素材Id返回素材的下载地址
export function getMaterialFileUrl(mediaId) {
    return window.global_config.BASE_URL + `/open/weixin/mp/api/downFile/${mediaId}`;
}


//根据素材Id返回素材图文列表
export function getMaterialNews(mediaId) {
    let url = `/internal/weixin/mp/material/news/${mediaId}`;
    return new Promise((resolve, reject) => {
        http.get(url).then(response => {
            resolve(response)
        });
    });
}


//上传微信公众号图文素材内的图片
export function uploadWxmpNewsImage(file) {
    let url = `/internal/weixin/mp/material/upload/newsImage`;
    return new Promise((resolve, reject) => {
        http.upload(url, file).then(response => {
            resolve(response)
        });
    });
}




//自动回复字典
export function wxmpReplyDict() {
    let url = `/internal/weixin/mp/reply/dict`;
    return new Promise((resolve, reject) => {
        http.get(url).then(response => {
            resolve(response.data.result)
        });
    });
}


//获取微信用户标签

export function wxmpTagDict() {
    let url = `/internal/weixin/mp/tag/dict`;
    return new Promise((resolve, reject) => {
        http.get(url).then(response => {
            resolve(response.data.result)
        });
    });
}




//===========================酒店模块档案开始==============================

export function hotelProfileDict() {
    let url = `/internal/hotel/profile/dict`;
    return new Promise((resolve, reject) => {
        http.get(url).then(response => {
            resolve(response.data.result)
        });
    });
}

export function hotelRoomTypeDict(hotelId) {
    let url = `/internal/hotel/room/type/dict/${hotelId}`;
    return new Promise((resolve, reject) => {
        http.get(url).then(response => {
            resolve(response.data.result)
        });
    });
}
